package com.loong.shop.controller.forehead;

import com.loong.common.mvc.BaseForeheadController;
import com.loong.common.param.BaseIdParam;
import com.loong.common.rest.Result;
import com.loong.common.validator.group.CommonValidate;
import com.loong.shop.handler.GoodsBrandHandler;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Description: 处理前台商品品牌请求的Controller
 * @Author: 刘群
 * @Date: 2020/10/27 9:25
 */
@RestController
@RequestMapping("forehead/shop/goodsBrand")
public class GoodsBrandForeheadController extends BaseForeheadController {

    @Resource
    private GoodsBrandHandler brandHandler;

    /**
     * 去重查询所有的商品品牌
     * @return 响应的结果
     */
    //TODO 商品品牌好像是唯一的，即使在不同分类下也不能有同样的商品品牌名称。因此这个接口貌似没用
    @PostMapping("find/distinct/brands")
    public Result findGoodsBrands(){
        return handlerExecutor.execute(() -> brandHandler.findBrandToForehead());
    }

    /**
     * 根据商品分类查询商品品牌
     * @param param 分类id
     * @return 响应的结果
     */
    @PostMapping("findByCategoryId")
    public Result findGoodsBrandsByCategoryId(@RequestBody @Validated({CommonValidate.class})BaseIdParam param){
        return handlerExecutor.execute(() -> brandHandler.findBrandsByCategoryIdToForehead(param.getId()));
    }

}
